#!/bin/bash
#
# Startup script for OpenSIPs
#
# chkconfig: 345 85 15
# description: OpenSIPs is a fast SIP Proxy.
#              And OpenSIPs is named OpenSER before
#
# processname: opensips
# pidfile: /var/run/opensips.pid

# Source function library.
. /etc/rc.d/init.d/functions

osips=/opt/telephony/opensips/sbin/opensips
osips_user=sip
osips_group=sip
fpid=/var/run/opensips.pid
prog=opensips
RETVAL=0

[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
        echo -n $"Starting $prog: "
        # there is something at end of this output which is needed to
        # report proper [ OK ] status in Fedora scripts
        daemon $osips -P $fpid -u $osips_user -g $osips_group $OPTIONS 2>/dev/null
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $osips
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog /var/run/$prog.pid
}

# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $osips
                RETVAL=$?
                ;;
        restart)
                stop
                start
                ;;
        condrestart)
                if [ -f /var/run/$prog.pid ] ; then
                        stop
                        start
                fi
                ;;
        *)
                echo $"Usage: $prog {start|stop|restart|condrestart|status|help}"
                exit 1
esac

exit $RETVAL

